﻿@{
    Uri url = new Uri(Request.Url.AbsoluteUri);
    ViewBag.Server = url.GetLeftPart(UriPartial.Authority);
    ViewBag.Title = "RVA Master Portal";
    string RafikiMasterVM = System.Configuration.ConfigurationManager.AppSettings["RafikiMasterVM"];
    string crudServiceBaseUrl = ViewBag.Server + "/api/";
    
  
}
<div id="BINDDIV-EMAIL">
    <h1 data-bind ="text: userName"></h1>
    <div id="subpage"></div>
</div>
<script>

    var emailModel = kendo.observable({
        emailSource:
            new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "@crudServiceBaseUrl" + "sqlsp/SP_SurveyData?StudentID=0",
                        // get blank data first time through
                        dataType: "json"
                    },
                    update: {
                        url: "@crudServiceBaseUrl" + "alltables/SurveyData",
                        dataType: "json",
                        type: "put"
                    },
                    destroy: {
                        url: "@crudServiceBaseUrl" + "alltables/SurveyData/Destroy",
                        dataType: "json"
                    },
                    create: {
                        url: "@crudServiceBaseUrl" + "alltables/SurveyData/Create",
                        dataType: "json"
                    },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }
                    }

                },
                batch: true,
                schema: {
                    model: {
                        id: "QuestionID"

                    }
                },
                error: function (e) {

                    alert("There appears to be a network error.\nCheck your connection and then click OK to try again.\n\nIf you keep getting this error, then there is a problem between you and the server.\nIn such a case, you may have to refresh the entire page and you may lose a small amount of your recent work.\n\nIf you KEEP having problems, email portalhelp@rva.org"); // displays "Invalid query"
                    surveyModel.surveySource.sync();
                },

                change: function (e) {
                    if (surveyModel.surveySource.hasChanges())
                        surveyModel.surveySource.sync();
                    surveyModel.set("view", this.view());
                    var data = this.data();
                    var done = true;
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Answer == null)
                            done = false;
                    }
                    if (done) {
                        $("#" + surveyModel.get("thisstudentID") + surveyModel.get("thiscourseID") + "LI").addClass("DONE");
                    }
                }
            })
    });
</script>

